package com.xiaoma.tpo.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaoma.tpo.dao.ForcastUserScoreDao;
import com.xiaoma.tpo.domain.ForcastUserScore;

@Service
public class ForcastUserScoreService {

	@Autowired
	private ForcastUserScoreDao userScoreDao;
	
	public int saveOrUpdate(ForcastUserScore score) {
		if(score.getId() != null) {
			return userScoreDao.update(score);
		}else {
			return userScoreDao.insert(score);
		}
	}
	
	public ForcastUserScore findByUserForcast(Integer userId, Integer questionId) {
		ForcastUserScore score = new ForcastUserScore();
		score.setUserId(userId);
		score.setQuestionId(questionId);
		List<ForcastUserScore> list = userScoreDao.findByColumns(score);
		if(list.size() > 0) {
			return list.get(0);
		}else {
			return null;
		}
	}
	
	public List<Map<String, Object>> findAllByUser(String groupIds, Integer userId) {
		
        return userScoreDao.findAllByUser(groupIds, userId);
	}
}
